<template>
  <div class="add-edit">
    <el-form :model="ruleForm"
             :rules="rules"
             ref="ruleForm"
             label-width="130px"
             class="yuyi-ruleForm">
      <el-form-item label="部门名称" prop="name">
        <el-input size="small" v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="部门代码" prop="name">
        <el-input size="small" v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="全宗号" prop="name">
        <el-select size="small" v-model="ruleForm.name" style="width: 100%">
          <el-option value="a"></el-option>
          <el-option value="b"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="类型" prop="name">
        <el-input size="small" v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="是否可用" prop="switch">
        <el-switch v-model="ruleForm.switch"></el-switch>
      </el-form-item>
      <el-form-item label="备注" prop="name">
        <el-input size="small" type="textarea" :autosize="autosize" v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="" prop="name">
        <el-button type="primary" size="small">{{ type === 'add' ? '确定新增' : '确定修改'}}</el-button>
        <el-button size="small" @click="handleCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'addEdit',
  props: {
    type: {
      type: String,
      default: () => 'add'
    },
    editData: {
      type: Object
    }
  },
  data () {
    return {
      autosize: {
        minRows: 4,
        maxRows: 6
      },
      ruleForm: {
        name: '',
        switch: false
      },
      rules: {
        name: [
          {
            required: true,
            message: '请输入活动名称',
            trigger: 'blur'
          },
          {
            min: 3,
            max: 5,
            message: '长度在 3 到 5 个字符',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    handleCancel () {
      // 关闭弹窗清空内容
      /* Object.keys(this.ruleForm).forEach((key) => {
        this.ruleForm[key] = ''
      }) */
      this.$emit('handleCancel')
    }
  }
}
</script>

<style lang="scss" scoped>
  .add-edit {
    padding-right: 40px;
  }
</style>
